import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { User } from '../../common/entities/user.entity';

@Entity('gallery_images')
export class GalleryImage {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'user_id', type: 'int', comment: '用户ID' })
  userId: number;

  @Column({ type: 'varchar', length: 100, comment: '图片名称' })
  name: string;

  @Column({ type: 'varchar', length: 500, comment: '图片URL' })
  url: string;

  @Column({ type: 'varchar', length: 500, nullable: true, comment: '缩略图URL' })
  thumbnail: string;

  @Column({ type: 'int', comment: '文件大小（字节）' })
  size: number;

  @Column({ type: 'int', nullable: true, comment: '图片宽度' })
  width: number;

  @Column({ type: 'int', nullable: true, comment: '图片高度' })
  height: number;

  @Column({ type: 'varchar', length: 10, nullable: true, comment: '图片格式' })
  format: string;

  @Column({ type: 'text', nullable: true, comment: '图片描述' })
  description: string;

  @CreateDateColumn({ 
    name: 'upload_time',
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    comment: '上传时间'
  })
  uploadTime: Date;

  @ManyToOne(() => User, user => user.galleryImages)
  @JoinColumn({ name: 'user_id' })
  user: User;
}
